const cloud = require('wx-server-sdk')
cloud.init({
  env:'edu-sdust-0gcxtlev1c3c5887'
})
const db = cloud.database();
const _ = db.command;
//订单表
const ORDER_TABLE = 'SDUST_ORDER';
// 云函数入口函数
exports.main = async (event, context) => {

  console.log('支付成功回调函数触发')
  console.log(event)
  let tradeno = event.outTradeNo;
  console.log(tradeno)
  try {
    let res = await db.collection(ORDER_TABLE).where({
      orderid:tradeno
    }).update({
      data:{
        orderstatus:1
      }
    })
    console.log(res)
  } catch (error) {
    return {
      errmsg: 'SERVER_ERROR',
      errcode: -1
    }
  }
  return {
    errmsg: 'SUCCESS',
    errcode: 0
  }
}